<?php
/*----------------------------------------------------------------------
 * 网络申请管理
 * Author: zheng.wang
----------------------------------------------------------------------*/

namespace Admin\Controller;

use Think\Controller;
class ApplyController extends AdminController {
	
	//添加代理商页面
	public function applyList(){
		/*查询条件*/ 
		//有效期查询
		if($_GET['create_time_start'] && $_GET['create_time_end']){
			$map['ctime'] = array(array('EGT',strtotime($_GET['create_time_start'])  ),array('ELT',strtotime($_GET['create_time_end'])+86400)) ;
		}elseif($_GET['create_time_start']){
			$map['ctime'] = array('EGT',strtotime($_GET['create_time_start']));
		}elseif($_GET['create_time_end']){
			$map['ctime'] = array('ELT',strtotime($_GET['create_time_end']));
		}
		if($_GET['status'] == 1){
			$map['status'] = 1;
		}elseif($_GET['status'] == 2){
			$map['status'] = 0;
		}
		$keywords = $_GET['keywords'];
		if($keywords){
			$map['phone'] = array('like',"%$keywords%");
		}
		if($keywords == '0'){
			$map['phone'] = array('like',"%$keywords%");
		}
		$count  = M('apply')->where($map)->count();// 查询满足要求的总记录数
		$Page   = new \Think\Page2($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(10)
		$show   = $Page->show();// 分页显示输出
		$list   = M('apply')->where($map)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$page_title = '网络申请';
		$this->assign('page_title',$page_title);  
		$this->assign('list',$list);    //数据列表
		$this->assign('page',$show);    //分页		
		$this->display();
	}
	
	public function update(){
		$userLogic = new \Common\Logic\UserLogic();
		//当前用户信息
        $user_info = $userLogic->getCurrentUserInfo();		
		$map['id'] = I('request.id');
		$info  = M('apply')->where($map)->find();
		$page_title = '处理';
		$this->assign(get_defined_vars());
		$this->display();
	}
	
	//状态更新
	public function updateAction(){
		$map['id'] = I('request.id');
		$user_info = session('user_info');
		$data['status'] = 1;
		$data['user_id'] = $user_info['user_id'];
		$result = M('apply')-> where($map)->setField($data);
		if($result != false){
			$msg['info'] = '处理成功';
			$msg['status'] = 1;
			$msg['url'] = U('Admin/Apply/applyList') ;
		}else{
			$msg['info'] = '处理失败';
			$msg['status'] = 2;
			$msg['url'] = U('Admin/Apply/applyList') ;
		}
		$this->ajaxReturn($msg);

	}	

	public function detail(){
		$map['id'] = I('request.id');
		$info  = M('apply')->where($map)->find();
		$page_title = '详情';
		$this->assign(get_defined_vars());
		$this->display();
	}	


}